﻿Public Class cls_Item_Update
    Inherits cls_Database_Base
#Region "Get FuncG_GetMaxCode"
    Public Function FuncG_GetMaxCode() As String
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT MAX(CAST(ID AS BIGINT)) FROM [TBL_ITEM] WHERE CAST(ID AS BIGINT) < 1000000000"
                Return FuncM_ExecuteScalar(mvStr_Sql)
            End If
        Catch ex As Exception
            Return "0"
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return "0"
    End Function
#End Region
#Region "Get Item"
    Public Function FuncG_GetAllData() As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT * FROM [TBL_ITEM] WHERE LOC_ID = @iNVChr_LOCID ORDER BY [ID]"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
    Public Function FuncG_GetAllData(ByVal iStr_GroupID As String) As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT * FROM [TBL_ITEM] WHERE LOC_ID = @iNVChr_LOCID AND GROUP_ID = @iNVChr_GROUPID ORDER BY CAST ([ID] AS INT)"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_GROUPID", iStr_GroupID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
    Public Function FuncG_GetDataInfo(ByVal iStr_ID As String) As DataTable
        Dim mvDataTale As New DataTable
        Dim mvStr_Sql As String = ""
        Try
            If FuncM_OpenConnection() Then
                mvStr_Sql = "SELECT * FROM [TBL_ITEM] WHERE LOC_ID = @iNVChr_LOCID AND [ID] = @iNVChr_ID"
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iStr_ID)
                mvDataTale = FuncM_GetDataTable(mvStr_Sql)
            End If
        Catch ex As Exception
            Throw ex
        Finally
            FuncM_CloseConnection()
        End Try
        Return mvDataTale
    End Function
#End Region
#Region "Update Item"
    Public Function FuncG_UpdateItem(ByVal iCls_Item As cls_Item, ByVal iFlag As Byte) As Boolean
        Try
            If FuncM_OpenConnection() Then
                SubM_AddParameter("@iNVChr_LOCID", gvStr_LocID)
                SubM_AddParameter("@iNVChr_ID", iCls_Item.ID)
                SubM_AddParameter("@iNVChr_NAME", iCls_Item.Name)
                SubM_AddParameter("@iFlt_PRICE1", iCls_Item.Price1)
                SubM_AddParameter("@iFlt_PRICE2", iCls_Item.Price2)
                SubM_AddParameter("@iNVChr_UNIT", iCls_Item.Unit)
                SubM_AddParameter("@iNVChr_PRINTER", iCls_Item.Printer)
                SubM_AddParameter("@iTInt_PRINT", iCls_Item.Print)
                SubM_AddParameter("@iTInt_STATUS", iCls_Item.Status)
                SubM_AddParameter("@iTInt_PROMAT", iCls_Item.Promat)
                SubM_AddParameter("@iTInt_Flag", iFlag)
                If FuncM_ExecuteStore("usp_Item") Then
                    Return True
                Else
                    Return False
                End If
            End If
        Catch ex As Exception
            Throw ex
            Return False
        Finally
            FuncM_CloseConnection()
        End Try
    End Function
#End Region
End Class
